<?php
    if ($deal == null )
    {
        echo 'No deals';
        return; 
    }
    
    $is_sold_out = ($deal->number_voucher_max <= $deal->count_voucher_buy) || ( $deal->time_to_expire <= 0);
    
?>
<link href="<?php echo TEMPLATE_CSS_PATH ;?>/deal_detail.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
    #Content {
        margin-bottom: 30px;
    }
  
.d-d-module-2 {
    float: right;
    width: 20%;
    
    
}

.content-right {
    float: left;
    width: 76.5%;
}
.category_title {
    border: 1px solid #DDD9E9 !important; 
    width: 98.8% !important;
    margin-bottom: 1%;
}
-->
</style>


<div class="page">
    <div class="category_title">
        <h2>
            <a href="/"><?=ALL_DEALS?></a> 
            &raquo; <a href="/categories/deals/<?=$deal->id_categories?>"><?=$deal->category_name?></a>  
            &raquo; <label class="normal"><?=$deal->deal_name?></label> 
        </h2>
    </div>
    
    

    <div class="d-d-module-body content-right">
  			<table style="width: 100%;">
  				<tr>
                    <td colspan="2">
                        <h2 class="d-d-title-item">
   			              <?=$deal->deal_name?>
                        </h2>
                        <span>
                            <?=$deal->description?>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <table style="width: 100%;">
                            <tr>
                                <td style="vertical-align: top;">
                                    <?php
                                        $op_sl_i = array();
                                        array_push($op_sl_i, $deal->picture1);
                                        array_push($op_sl_i, $deal->picture2);
                                        array_push($op_sl_i, $deal->picture3);
                                        array_push($op_sl_i, $deal->picture4);
                                        array_push($op_sl_i, $deal->picture5);
                                        $this->load->view('render/deal_image_slide',array('arr_img'=>$op_sl_i));
                                    ?>        
                                </td>
                                <td style="vertical-align: top;width:40%;">
                                    <!-- Begin payment price -->
                                    <div class="payment_price">
                                        <span>FROM</span><br />
                                        <span class="payment_price_text">$<?=$deal->payment_price?></span>
                                    </div>
                                    <!-- End payment price -->
                                    <!-- Begin price -->
                                    <div class="deal-discount">
                                      <table style="width:100%">
                                        <tbody>
                                        <?php if($deal->view == VIEW_PRICE):  //display price?>
                                            <thead>
                                                <td style="width: 33%;">Price</td>
                                                <td style="width: 33%;">Special Price</td>
                                                <td>You Save</td>
                                            </thead>
                                            <tr>
                                                <td>$<?=$deal->price;?></td>
                                                <td>$<?=$deal->special_price;?></td>
                                                <td>$<?=$deal->price - $deal->special_price?></td>
                                            </tr>
                                        <?php elseif($deal->view == VIEW_PERCENT): ?>
                                          <thead>
                                            <td style="width: 33%;">Price</td>
                                            <td style="width: 33%;">Discount</td>
                                            <td>You Save</td>
                                          </thead>
                                          <tr>
                                            <td>$<?=$deal->price;?></td>
                                            <td><?=100 - (int)($deal->special_price * 100 / $deal->price);?>%</td>
                                            <td>$<?=$deal->price - $deal->special_price?></td>
                                          </tr>
                                          <?php endif; ?> 
                                        </tbody>
                                      </table>
                                    </div>
                                    <!-- End price -->
                                
                                    <!-- Begin bought -->
                                    <div class="deal-bought">
                                        <span class="deal-bought-text">Bought</span>
                                        <span class="deal-bought-value"><?=$deal->count_voucher_buy?>/<?=$deal->number_voucher_max?> (Vouchers)</span>
                                    </div>
                                    <!-- End bought -->
                                    
                                    <!-- Begin Limited time -->
                                    <?php if(!$is_sold_out):?>
            				        <div class="limited-time" id="countdown_timer_div">
                                        <span class="countdown-label">Limited Time Only!</span>
                                        <span id="countdown_timer_id" class="countdown-timer"></span>
                                    </div>
                                    <?php endif; ?>
                                    <!-- End limited time -->
                                    <!-- Begin button -->
                                    <div class="action">
                                        <?php if($is_sold_out):?>
                                        <span class="btn-sold-out-big" href="#" id="sold-out-link">SOLD OUT</span>
                                        <?php else: ?>
                                        <span class="btn-sold-out-big" href="#" style="display: none;" id="sold-out-link">SOLD OUT</span>
                                        <a class="btn-add-to-cart-big" href="javascript:addtolist('<?=base64_encode('deal_'.$deal->id);?>')" id="add-to-cart-link" >Add to cart</a>
                                        <?php endif; ?>
                                    </div>
                                    <!-- End button -->
                                </td>
                            </tr>
                        </table>
                        
  					   
                    </td>
  				</tr>
                <tr>
                    <td style="width: 50%;">
                        <div class="description_item">
				            <h2 class="description_title">Business info</h2>
				            <?=$deal->deal_business?>
    				    </div>
                    </td>
                    <td style="width: 50%;">
                        <div class="description_item">
				            <h2 class="description_title">Conditions</h2>
				            <?=$deal->deal_conditions?>
				        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="description_item">
				            <h2 class="description_title">Description</h2>
				            <?=$deal->deal_information?>
				        </div>
                    </td>
                </tr>
  			</table>
    </div>
    
    <div class='d-d-module-2'>
        <?=$this->load->view('render/menu-vertical-categories',array('category'=>$categories,'deal'=>$deal)); ?>    
    </div>
    
</div>

<script type="text/javascript">
<!--
	<?php if(!empty($deal->end_day) && $deal->time_to_expire > 0 && !$is_sold_out):?>
$('#countdown_timer_div').show();
$('#countdown_timer_id').countdown({ 
    until: <?=$deal->time_to_expire?>, layout: ' <img width="32px"  style="vertical-align: middle;" src="<?=TEMPLATE_IMAGE_PATH?>/timer.png"> {dnn} {dl} {hnn}:{mnn}:{snn}',
    onExpiry: function(){
    	$('#sold-out-link').show();
    	$('#add-to-cart-link').hide();
    }
    });
<?endif?> 
-->
</script>